import React from 'react'
// ===================================================================== Temp
import SubmitForm from '#cpt/temp/SubmitForm'
// ===================================================================== global declare
const { $fn, $http, $Lazy } = window
// ===================================================================== antd
const $cache = $Lazy.file(()=>import('#private/cache-api'))
// ===================================================================== component
class Index extends React.Component{
	state = {
		formData: [
			{ label: '标本条码',		name: 'spec_code',  		half:true, required:true, disabled:true },
			{ label: '送检单位',		name: 'inspec_unit_id',  	half:true, required:true, type:'select', onValue:({ rows })=>{
				if(rows){
					this.submit = { ...this.submit, inspec_unit: rows['name']}
				}else{
					delete this.submit['inspec_unit']
				}
			} },
			{ label: '自然项目',		name: 'kind_id',  			full:true, required:true, type:'select', idStr:'kind_id', nameStr:'kind_name', 
				onValue:({ rows,value })=>{
					if(rows){
						this.submit = { ...this.submit, kind_name: rows['kind_name']}
					}else{
						delete this.submit['kind_name']
					}
					$http.submit(null,'sp-customer-log/kindId',{ param:{ kind_id:value, spec_code:this.props.backData.spec_code}}).then(data=>{
						
						this.formRef.setValue({major_group:data[0].major_group_id})
					})
				}
			},
			{ label: '送检科室',		name: 'depart_name',  		half:true, required:true },
			{ label: '岗位',		name: 'major_group',  		half:true, required:true, type:'select' },
			{ label: '回顾',		name: 'look_back',  		half:true, required:true, type:'select' },
			{ label: '沟通类型',		name: 'type',  				half:true, required:true, type:'select' },
			{ label: '反馈人',		name: 'contact_user',  		half:true, required:true },
			{ label: '联系电话',		name: 'phone',  			half:true, required:true },
			{ label: '联系日期',		name: 'contact_at',  		half:true, required:true, type:'date-time', format:1 },
			{ label: '反馈内容',		name: 'inspec_content',  	full:true, type:'textarea' },
			{ label: '客服处理',		name: 'contact_reason',  	full:true, type:'textarea' },
		]
	}
	
	model = {}
	submit = {}
	
	componentDidMount(){
		this.getModalSelect()
	}
	
	onSubmit = () => this.formRef.submit()
	clear = () => this.formRef.reset()
	
	setValue = async rows => {
		this.clear()
		await $cache.then(f => {
			const { formData } = this.state
			// 自然项目
			$fn.setRow(formData, 'kind_id', this.props.natureData )
			// 
			this.setState({ formData })
			this.formRef.setValue(this.props.backData)
		})
	}
	
	// 获取弹窗下拉
	getModalSelect = async () => {
		const { formData } = this.state
		$fn.setModalRows(formData, ['inspec_unit_id', 'major_group', 'look_back', 'type'], ()=>{
			$cache.then( async f => {
				// 送检单位
				$fn.setRow(formData, 'inspec_unit_id', await f.getCache({api:'hospital'}))
				// 岗位
				$fn.setRow(formData, 'major_group', await f.getCache({ api:'gang_wei' }) )
				// 回顾
				$fn.setRow(formData, 'look_back', await f.retrospect)
				// 沟通类型
				$fn.setRow(formData, 'type', await f.communication_type)
				// 
				this.setState({ formData })
			})
		})
	}
	
	render(){
		return SubmitForm.call(this, { labelWidth:'s6', api:'sp-customer-log/add' })
	}
}

export default Index